package com.nuoniu.sibanyun.service.finance.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.entity.dto.AccountingAuxiliaryLedgerDto;
import com.nuoniu.sibanyun.entity.dto.AccountingLedgerDto;
import com.nuoniu.sibanyun.entity.finance.VAccountingLedger;
import com.nuoniu.sibanyun.entity.finance.VAccountingSearchProgramme;
import com.nuoniu.sibanyun.entity.finance.VAccountingVoucherDetail;
import com.nuoniu.sibanyun.mapper.finance.VAccountingVoucherDetailMapper;
import com.nuoniu.sibanyun.service.finance.IVAccountingVoucherDetailService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 会计凭证细表 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-04-09
 */
@Service
public class VAccountingVoucherDetailServiceImpl extends ServiceImpl<VAccountingVoucherDetailMapper, VAccountingVoucherDetail> implements IVAccountingVoucherDetailService {

    @Override
    public Integer getByAccountingId(Long id) {
        return baseMapper.getByAccountingId(id);
    }

    @Override
    public List<VAccountingVoucherDetail> getAccountingAmount(String accountingIds) {
        return baseMapper.getAccountingAmount(accountingIds);
    }

    @Override
    public List<VAccountingLedger> countAccounting(VAccountingSearchProgramme searchProgramme) {
        return baseMapper.countAccounting(searchProgramme);
    }

    @Override
    public void updateStatus(String aIds) {
        baseMapper.updateStatus(aIds);
    }

    @Override
    public List<AccountingLedgerDto> getLedgerDetailList(VAccountingSearchProgramme searchProgramme) {
        return baseMapper.getLedgerDetailList(searchProgramme);
    }

    @Override
    public List<AccountingAuxiliaryLedgerDto> getAuxiliaryLedgerDetailList(VAccountingSearchProgramme searchProgramme) {
        return baseMapper.getAuxiliaryLedgerDetailList(searchProgramme);
    }

    @Override
    public VAccountingVoucherDetail getManDetail(Long mainId) {
        VAccountingVoucherDetail detail = baseMapper.getOne(mainId);
        VAccountingVoucherDetail amount = baseMapper.getSumAmount(mainId);
        if (amount ==null || detail== null)
        {
            throw new NuoNiuException("存在异常数据，请联系系统管理员");
        }
        detail.setDebitAmount(amount.getDebitAmount());
        detail.setCreditAmount(amount.getCreditAmount());
        return detail;
    }
}
